<?php

namespace app\index\model;

use think\Model;

class User extends Model
{
    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = 'created';
    protected $updateTime = false;

    public static function checkLogin($data)
    {
        $user = self::where(array('username' => $data['username']))->find();
        if (password_verify($data['password'], $user['password'])) {
            return array('result' => true, 'user' => $user);
        } else {
            return array('result' => false);
        }
    }

    public static function getGrouper()
    {
        return self::where(array('rights' => 2))->select();
    }

    public static function clearGroup($groupId)
    {
        self::where(array('group_id' => $groupId))->setField('group_id', '');
    }
}
